﻿$(function(){



	var d = domain.getcanshu().d

	var index = layer.load(1, {
	  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});

	//调试先闭

	wxCloud.cloud().callFunction({
		name:'getzanmeiWhereId',
		data:{
			_id:d
		},
		success:function(res){

			var data = res.result.data[0]
			$('title').text( data['xuhao']+"."+data['mulu'])
			var bb = jm(data['xuhao']+data['mulu'])
			var url = "https://7372-srrz-2g24l1oea7a7e67e-1304952114.tcb.qcloud.la/all/dmt/"+bb+".jpg"
			console.log(bb)
			$('audio')[0].src=url.replace("jpg","mp3")
			$('#imgp')[0].src=url

			$('#imgp')[0].onload = function(){

				layer.close(index)
				

				$(".bgimg").hide()


				b()



			}

			$('#imgp')[0].onerror = function(){
				
				$("#imgp").hide()

				if(data.lyric !== ''){
					var lyric = data.lyric
					var lyricArr = lyric.split(/,|。|，| /g)
					lyricArr.splice(0, 0, data.mulu);
					var navListText = doT.template($("#lyricTemp").text());
					$(".lyric").html(navListText(lyricArr));
					$(".lyric").show()
					$(".bgimg").show()
					layer.close(index)

				}else{

					layer.close(index)

				}
				
			}

			$("audio")[0].onerror = function(e){

				$(".play").hide()

				$(".title").hide()

				// $('.uploadBox').show()

			}

			//先关闭赞美访问数据上传
			// return
			var addData = {
					
					zId:data['_id'],
					xuhao:data['xuhao'],
					mulu:data['mulu'],
					openId:lsa.get('openid')
			}

			wxCloud.addZanMeiFangWen(addData,function(res){
				console.log(res)
			})

		},
		fail:function(erro){

			console.log(erro)

		}
	})


	//进度条拖拽事件监听
	dragProgress($("#progress")[0],$("#proressCnl")[0],

		function(val){ //开始

			console.log(val)
			
			var b = $('audio')[0].paused //获取audio的初始状态
			this.stPaused = b
			if(!b){
				$('audio')[0].pause()
			}
			
		},
		function(val){ //移动
			console.log(val)
		},
		function(val){ //结束
			
			var a = $('audio')[0].duration * (val/100)

			$('audio')[0].currentTime = a
			if(!this.stPaused){
				$('audio')[0].play()
			}

		}
	)


	//audio控制
	$("#playcnl").click(function(e){

		
		var className = $(this).attr('class')
		
		if(className.indexOf("glyphicon-play")!==-1){


			$(this).addClass('glyphicon-pause').removeClass('glyphicon-play')

			$('audio')[0].play()


		}else{

			$(this).addClass('glyphicon-play').removeClass('glyphicon-pause')
			$('audio')[0].pause()

		}


		$('audio')[0].onplay = function(){
			
			$(this).addClass('glyphicon-pause').removeClass('glyphicon-play')
		}

		$('audio')[0].onpause = function(){
			$(this).addClass('glyphicon-pause').removeClass('glyphicon-play')

			
		}

		$('audio')[0].ontimeupdate = function(e){

			widthCss($("#proressCnl")[0],$('audio')[0].currentTime / $('audio')[0].duration * 100)
		}

		$('audio')[0].onended = function(e){

			$('#playcnl').addClass('glyphicon-play').removeClass('glyphicon-pause')
			
			widthCss($("#proressCnl")[0],0)

			$('audio')[0].play()

			$('#playcnl').addClass('glyphicon-pause').removeClass('glyphicon-play')
			
		}
	})

	$("#upload").click(function(e){
		console.log('上传文件的服务')
		
	})

	//响应式图片显示
	a()
	
	
	$(window).resize(function(){
		
		a()
		b()
	})

	function a(){ //图片响应式处理逻辑 

			var winW = $(this).width()

			if(winW>620){

				$("#pagetwo").attr('class','container page computer')

			}else{

				$("#pagetwo").attr('class','container page')
			}


			
	}

	function b(){ //图片在窗体口的位置响应式处理


		var imgH = $("#imgp").height()

		var mainH =$(".main").height()

		if(mainH > imgH){
			$("#imgp").attr("class","ximgp")
		}else{
			$("#imgp").attr("class","")
		}

	}

	$(".main").click(function(){ //点击main控制header and footer 的显示和隐藏 


		if(this.navShow == undefined){
			this.navShow = true
		}

		var seed = 500

		if(this.navShow){

			$("#header").animate({top:"-40px"},seed)
			$(".footer").animate({bottom:"-40px"},seed)
			this.navShow = false

		}else{

			$("#header").animate({top:0},seed)
			$(".footer").animate({bottom:0},seed)
			this.navShow = true
		}
	})



})